import { IPSAppView } from '../../app/view/ipsapp-view';
import { IPSPicker } from './ipspicker';
import { PSPickerEditorImpl } from './pspicker-editor-impl';

export class PSPickerImpl extends PSPickerEditorImpl implements IPSPicker {
  get dropDownViewHeight(): number {
    return this.M.dropDownViewHeight;
  }

  get dropDownViewWidth(): number {
    return this.M.dropDownViewWidth;
  }

  protected linkpsappview: IPSAppView | null = null;

  getLinkPSAppView(): IPSAppView | null {
    if (this.linkpsappview != null) return this.linkpsappview;
    const value = this.M.getLinkPSAppView;
    if (value == null) {
      return null;
    }
    this.linkpsappview = this.getPSModel4('app.view.IPSAppView', value, 'getLinkPSAppView') as IPSAppView;
    return this.linkpsappview;
  }

  get linkPSAppView(): IPSAppView | null {
    return this.getLinkPSAppView();
  }

  getLinkPSAppViewMust(): IPSAppView {
    const value = this.getLinkPSAppView();
    if (value == null) {
      throw new Error('未指定数据链接视图');
    }
    return value;
  }

  get dropDownView(): boolean {
    return this.M.dropDownView != null ? this.M.dropDownView : false;
  }

  get enableLinkView(): boolean {
    return this.M.enableLinkView != null ? this.M.enableLinkView : false;
  }

  get enablePickupView(): boolean {
    return this.M.enablePickupView;
  }

  get singleSelect(): boolean {
    return this.M.singleSelect;
  }

  get cls(): string {
    return 'PSPickerImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.editor.IPSPicker' || cls == 'control.editor.IPSValueItemEditor') return true;
    return super.instanceof(cls);
  }
}
